$(function() {
	//保存信息功能
	$("#save").click(function(){
		var phoneNo = localStorage.getItem("phoneNo");
		var userName = $("#name").val();
		var age = $("#age").val();
		var sex = $("#sex option:selected").val();
		var certNo = $("#certNo").val();
		var profession = $("#profession option:selected").val();
		var monthIncome = $("#income").val();
		var isCreditCard = $("#isCreditCard option:selected").val();
		var region = $("#region").val();
		
		
		var myreg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
		if(!myreg.test(certNo)) 
		{ 
		    alert('请输入有效的身份证号码！'); 
		    return false; 
		}
		
		var data = {
						"params": {
							"phoneNo": phoneNo,
			       			"userName": userName,
			       			"age": age,
			       			"sex": sex,
			       			"certNo": certNo,
			       			"profession": profession,
			       			"monthIncome": monthIncome,
			       			"isCreditCard": isCreditCard,
			       			"region": region
			   			 }
			   		}
		var jsonData = JSON.stringify(data);
		console.log(jsonData);
		$.ajax({
			url: urlLink + "/bMaMarketCustInfo/perfectInfo",
			type: "POST",
			contentType: "application/json; charset=utf-8",
			data:jsonData,
			success:function(data){
				if (data.code == "0000") {
					/*var id = data.result.receToken;
					localStorage.setItem("token", token);*/
					window.location.href = "personal.html";

				}else{
					alert(data.msg);
				}
			},
			error: function(data){
				console.log(data);
				alert("服务器繁忙");
			}
		})
	});

});

//加载查询的用户信息
function queryInfo(){
	var userName     = (GetUrlParameter("userName") == "null")?"" : GetUrlParameter("userName");
	var age          = (GetUrlParameter("age") == "null")? "" : GetUrlParameter("age");
	var profession   = (GetUrlParameter("profession") == "null" )? "" : GetUrlParameter("profession");
	var sex          = (GetUrlParameter("sex") == "null")? "" : GetUrlParameter("sex");
	var certNo       = (GetUrlParameter("certNo") == "null" )? "" : GetUrlParameter("certNo");
	var monthIncome  = (GetUrlParameter("monthIncome") == "null" )? "" : GetUrlParameter("monthIncome");
	var isCreditCard = (GetUrlParameter("isCreditCard") == "null" )? "" : GetUrlParameter("isCreditCard");
	var region       = (GetUrlParameter("region") == "null")? "" : GetUrlParameter("region");
	$("#name").val(userName);
	$("#age").val(age);
	$("#profession").val(profession);
	$("#sex").val(sex);
	$("#certNo").val(certNo);
	$("#income").val(monthIncome);
	$("#isCreditCard").val(isCreditCard);
	$("#region").val(region);
}

//获取url后的参数
function GetUrlParameter(variable) {
	var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
	    var pair = vars[i].split("=");
	    if(pair[0] == variable){
	    	return decodeURI(pair[1]);  //decodeURI方法对中文解码
	    }
    }
    return false;
}